package com.learn;

import com.learn.DesignPattern.Singleton.*;

/**
 * 测试单例模式
 */
public class TestDesignSingleton {
    public static void main(String[]  args) {
        SingletonStatic singleton= SingletonStatic.getInstance();
        singleton.getName();
        SingletonStatic singleton1= SingletonStatic.getInstance();
        singleton1.getName();
        if(singleton==singleton1){
            System.out.println("same");
        }else {
            System.out.println("not same");
        }

        System.out.println("=======================================");
        SingletonDoubleLock singletonDoubleLock = SingletonDoubleLock.getInstance();
        singletonDoubleLock.getName();
        System.out.println("-------------------------------------");
        SingletonDoubleLock singletonDoubleLock1 = SingletonDoubleLock.getInstance();
        singletonDoubleLock1.getName();
        if(singletonDoubleLock==singletonDoubleLock1){
            System.out.println("same");
        }else {
            System.out.println("not same");
        }

        System.out.println("=======================================");
        SingletonLazy singletonLazy = SingletonLazy.getInstance();
        singletonLazy.getName();
        SingletonLazy singletonLazy1 = SingletonLazy.getInstance();
        singletonLazy1.getName();
        if(singletonLazy==singletonLazy1){
            System.out.println("same");
        }else {
            System.out.println("not same");
        }

        System.out.println("=======================================");
        SingletonLazySafety singletonLazySafety = SingletonLazySafety.getInstance();
        singletonLazySafety.getName();

        SingletonLazySafety singletonLazySafety1 = SingletonLazySafety.getInstance();
        singletonLazySafety1.getName();
        if(singletonLazySafety==singletonLazySafety1){
            System.out.println("same");
        }else {
            System.out.println("not same");
        }
        System.out.println("=======================================");
        SingletonStarve singletonStarve = SingletonStarve.getInstance();
        singletonStarve.getName();

        SingletonStarve singletonStarve1 = SingletonStarve.getInstance();
        singletonStarve1.getName();
        if(singletonStarve==singletonStarve1){
            System.out.println("same");
        }else {
            System.out.println("not same");
        }

    }
}
